home *** CD-ROM | disk | FTP | other *** search
- // This unit registers the ODBC dictionary component of Multilizer.
- //
- // Copyrights 1995-1998 Innoview Data Technologies Oy
-
- unit IvODBCReg;
-
- {$I IVMULTI.INC}
-
- interface
-
- procedure Register;
-
- implementation
-
- uses
- Windows, Classes, Controls, DsgnIntf, SysUtils,
- {$IFNDEF VER93}
- ODBC, IvODBCDic, IvConnection, IvPassWD;
- {$ENDIF}
-
- {$IFNDEF VER93}
-
- // TIvODBCTableNameProperty
-
- type
- TIvODBCTableNameProperty = class(TStringProperty)
- public
- function GetAttributes: TPropertyAttributes; override;
- procedure GetValues(Proc: TGetStrProc); override;
- end;
-
- var
- connection: TIvConnection;
-
- function TIvODBCTableNameProperty.GetAttributes: TPropertyAttributes;
- begin
- Result := [paMultiSelect, paValueList, paSortList, paRevertable];
- end;
-
- procedure TIvODBCTableNameProperty.GetValues(Proc: TGetStrProc);
- var
- dialog: TIvPasswordDialog;
- resultSet: TIvResultSet;
- dictionary: TIvODBCDictionary;
- begin
- dictionary := GetComponent(0) as TIvODBCDictionary;
-
- // If the data source has changed since last connect, closes the connection
-
- if dictionary.DataSource <> connection.DataSource then
- connection.Close;
- connection.DataSource := dictionary.DataSource;
-
- // Connects to the database
-
- while True do
- begin
- // If the connection is not active and the user name/password was not given
- // ask them.
-
- if (not connection.Active) and
- ((dictionary.UserName = '') or (dictionary.Password = '')) then
- begin
- // No user id given. Asks one
-
- dialog := TIvPasswordDialog.Create(nil);
- try
- dialog.UserName.Text := dictionary.UserName;
- dialog.Password.Text := dictionary.Password;
- if dialog.ShowModal = mrOK then
- begin
- connection.UserName := dialog.UserName.Text;
- connection.Password := dialog.Password.Text;
- end
- else
- Exit;
- finally
- dialog.Free;
- end;
- end;
-
- resultSet := nil;
- try
- connection.Open;
-
- resultSet := connection.SelectTables;
- while resultSet.Next do
- begin
- if CompareText(resultSet.Columns[3].AsString, 'TABLE') = 0 then
- Proc(resultSet.Columns[2].AsString);
- end;
- resultSet.Free;
- Break;
- except
- resultSet.Free;
- connection.Close;
- dictionary.UserName := '';
- dictionary.Password := '';
- raise;
- end;
- end;
- end;
-
- // TIvDataSourceProperty
-
- type
- TIvDataSourceProperty = class(TStringProperty)
- public
- function GetAttributes: TPropertyAttributes; override;
- procedure GetValues(Proc: TGetStrProc); override;
- end;
-
- function TIvDataSourceProperty.GetAttributes: TPropertyAttributes;
- begin
- Result := [paMultiSelect, paValueList, paSortList, paRevertable];
- end;
-
- procedure TIvDataSourceProperty.GetValues(Proc: TGetStrProc);
- var
- i: Integer;
- begin
- for i := 0 to IvEnvironment.DataSourceCount - 1 do
- Proc(IvEnvironment.DataSources[i].ServerName);
- end;
- {$ENDIF}
-
- procedure Register;
- begin
- {$IFNDEF VER93}
- // ODBC dictionary
-
- if not IsODBCAvailable then
- Exit;
-
- RegisterComponents('Multilizer', [TIvODBCDictionary]);
-
- RegisterPropertyEditor(
- TypeInfo(String),
- TIvODBCDictionary,
- 'TableName',
- TIvODBCTableNameProperty);
-
- RegisterPropertyEditor(
- TypeInfo(String),
- TIvODBCDictionary,
- 'LanguageTableName',
- TIvODBCTableNameProperty);
-
- RegisterPropertyEditor(
- TypeInfo(String),
- TIvODBCDictionary,
- 'LocaleTableName',
- TIvODBCTableNameProperty);
-
- RegisterPropertyEditor(
- TypeInfo(String),
- TIvODBCDictionary,
- 'DataSource',
- TIvDataSourceProperty);
- {$ENDIF}
- end;
-
- {$IFNDEF VER93}
- initialization
- if IsODBCAvailable then
- connection := TIvConnection.Create
- else
- connection := nil;
- finalization
- connection.Free;
- {$ENDIF}
- end.
-